package com.ce.pms.customer.web;

import com.ce.pms.common.model.SysrefcodeDO;
import com.ce.pms.customer.service.IHisResidentService;
import com.ce.pms.customer.vo.CustSearchVO;
import com.ce.util.BlankUtil;
import com.sitechasia.webx.components.xtable.util.ExtremeUtils;
import com.sitechasia.webx.core.annotation.Out;
import com.sitechasia.webx.core.annotation.Read;
import com.sitechasia.webx.core.annotation.Scope;
import com.sitechasia.webx.core.support.Page;

public class HisResidentAction  extends CustomerAction {
	private IHisResidentService hisResidentService;



	public void setHisResidentService(IHisResidentService hisResidentService) {
		this.hisResidentService = hisResidentService;
	}


	public IHisResidentService getHisResidentService() {
		return hisResidentService;
	}

	/***
	 * Function: 居住历史普通与高级查询方法
	 * @param customerSearch
	 * @param pageNO
	 * @param pageSize
	 * Create author:燕大为
	 * Create on:2008-6-6
	 * Edit author:
	 * Edit on:
	 * Why:
	 */

	public String queryHisResInfo(CustSearchVO customerSearch, Integer pageNO, Integer pageSize)
	{
		String sortStr=ExtremeUtils.getOrderString(this.getRequest());
		customerSearch.setOrderString(sortStr);
		wrapCustSearchVO(customerSearch);
		Page page = hisResidentService.queryHisresInfo(customerSearch, pageNO, pageSize);
		setAttribute("hisResidentList", page.getResult());
		setAttribute("totalRows", page == null ? new Integer(0) : new Integer(new Long(page.getTotalCount()).intValue()));
		return "queryHisResInfo";
	}


	/***
	 * Function: 居住历史列表显示
	 * @param pageNO
	 * @param pageSize
	 * @return
	 * Create author:燕大为
	 * Create on:2008-7-4
	 * Edit author:
	 * Edit on:
	 * Why:
	 */
	public String queryHisResList(
			@Read(key = "ec_p",defaultValue="1")	Integer pageNO,
			@Read(key = "ec_crd",defaultValue="15") Integer pageSize)
	{
		CustSearchVO custSearchVO;
		Object obj = getAttribute("custsearchVO",Scope.SESSION);
		custSearchVO = (obj==null ? new CustSearchVO() : (CustSearchVO)obj);
		return queryHisResInfo(custSearchVO, pageNO, pageSize);
	}

	/**
	 * Function:跳转到高级查询页面hisResidentSearch.jsp
	 * Create author:燕大为
	 * Create on:2008-5-26
	 * Edit author:
	 * Edit on:
	 * Why:
	 */
	public void initACSearch(){}


	/***
	 * Function: 居住历史查询主界面
	 *
	 * Create author:燕大为
	 * Create on:2008-6-6
	 * Edit author:
	 * Edit on:
	 * Why:
	 */
	public void initHisResidentSearch(@Read(key="houseNumber")@Out(key="houseNumber")String houseNumber,
									  @Read(key="isShowMenu",defaultValue="true")@Out(key="isShowMenu")String isShowMenu)
	{}


	/**
	 * Function:初始化列表页面，根据业务需要，<br/>
	 * 			这里仅做页面跳转,初始时不做查询
	 * Create author:燕大为
	 * Create on:2008-5-26
	 * Edit author:
	 * Edit on:
	 * Why:
	 */
	public String initHisResidentList()
	{
		this.setAttribute("totalRows", new Integer(0));
		return "initResidentList";
	}
	/**
	 * Function:将查询条件保存至session,高级查询时将调用本方法,然后再由页面调用queryHisResList方法
	 * @param custsearchVO
	 * Create author:燕大为
	 * Create on:2008-7-4
	 * Edit author:
	 * Edit on:
	 * Why:
	 */
	public void setCustsearchVOCache(@Read	CustSearchVO custsearchVO) {
		setAttribute("custsearchVO", custsearchVO,Scope.SESSION);
	}



	/***
	 * Function: 数据转换用于将前台数据customerType与participantType转换为后台所需数据
	 * @param cust
	 * Create author:燕大为
	 * Create on:2008-7-7
	 * Edit author:
	 * Edit on:
	 * Why:
	 */
	private void wrapCustSearchVO(CustSearchVO cust)
	{
		if(!BlankUtil.isBlank(cust.getCustomerType()))
		{
			SysrefcodeDO sysCode =  sysrefcodeService.findSysrefcodeById(Long.parseLong(cust.getCustomerType()));
			String value = sysCode.getValue();
			cust.setCustomerType(value);
		}
		if(!BlankUtil.isBlank(cust.getParticipantType()))
		{
			SysrefcodeDO sysCode =  sysrefcodeService.findSysrefcodeById(Long.parseLong(cust.getParticipantType()));
			String value = sysCode.getValue();
			cust.setParticipantType(value);
		}
	}



}
